<template>
  <div class="message-container">
    <div class="content">
      <div class="top">
        <div class="title-wrapper">
          <div class="title">消息</div>
        </div>
        <el-button @click="readAll">全部已读</el-button>
      </div>
    </div>
    <div class="bottom" :style="[{height: height + 'px'},{overflowY:'scroll'}]">
      <el-row v-for="(item ,index) of list" :key="index">
        <el-col :span="24">
          <div class="d-flex row-box">
            <div class="left">
              <el-badge :is-dot="item.is_read == 0" class="item">
                <div class="title d-flex">
                  <p class="txt mr-10">{{ item.title }}</p>
                  <p class="date">{{ item.created_at }}</p>
                </div>
                <div class="desc">{{ item.content }}</div>
              </el-badge>
            </div>
            <div class="right">
              <!-- <el-popover
                placement="bottom"
                :title="item.title"
                width="200"
                trigger="click"
                :content="item.content"
              >
                <span slot="reference" class="col-blue">查看详情</span>
              </el-popover>-->
              <span slot="reference" class="col-blue" @click="lookDetail(item)">查看详情</span>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
    <Pagination class="pagination" :pageSizes="10" :total="total" @nextPage="handleNextPage" />
  </div>
</template>
<script>
import Pagination from "@/common/pagination";
import Resize from "@/common/mixins/resize";
import { getNewsList, readAllNews } from "@/api/http/news";

export default {
  components: {
    Pagination
  },
  mixins: [Resize],
  data() {
    return {
      total: 0,
      page: 1,
      list: [
        {
          title: "设计师付款通知",
          date: "2019-08-07  13:00:00",
          desc: "设计师玛丽亚申请入驻，支付金额298"
        }
      ],
      height: 0,
      defaultHeight: 280
    };
  },
  created() {
    this.getNewsList();
  },
  methods: {
    // 查看消息详情
    lookDetail(item) {
      console.log(item, "---item");
      if (item.title == "新活动报名通知") {
        this.$router.push("/activity/sign-up");
      } else if (item.title == "新增客户提醒") {
        this.$router.push("/client/order");
      } else if (item.title == "新商品兑换通知") {
        this.$router.push("/integral/order");
      } else if (item.title == "设计师申请通知") {
        this.$router.push("/designer/apply-list");
      }
    },
    handleNextPage(page) {
      this.page = page;
      this.getNewsList();
    },
    // 获取消息列表
    getNewsList() {
      getNewsList({ page: this.page }).then(res => {
        if (res.code == 200) {
          this.list = res.data.data;
          this.total = res.data.total;
        }
      });
    },
    readAll() {
      readAllNews().then(res => {
        if (res.code == 200) {
          this.$message.success("已读成功");
          this.getNewsList();
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
@import "@/styles/el-button.scss";
@import "@/styles/color.scss";
@import "@/styles/el-pagination.scss";
.message-container {
  .content {
    .top {
      width: 100%;
      box-sizing: border-box;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 10px 0;
      .title-wrapper {
        display: flex;
        align-content: center;
        .title {
          height: 44px;
          line-height: 44px;
          color: rgba(68, 68, 68, 1);
          font-size: 18px;
          font-family: Roboto;
          font-weight: bold;
          cursor: pointer;
        }
      }
    }
    .bottom {
    }
  }
}
.row-box {
  .left {
    flex: 1;
    .title {
      .txt {
        line-height: 29px;
        color: rgba(68, 68, 68, 1);
        font-size: 16px;
        text-align: left;
        font-family: SourceHanSansSC-bold;
        font-weight: bold;
      }
      .date {
        line-height: 20px;
        color: rgba(189, 189, 189, 1);
        font-size: 12px;
        text-align: left;
        font-family: SourceHanSansSC-regular;
      }
    }
    .desc {
      line-height: 29px;
      color: rgba(68, 68, 68, 1);
      font-size: 14px;
      text-align: left;
      font-family: SourceHanSansSC-regular;
    }
  }
  .right {
    width: 200px;
  }
}
.el-row {
  margin-bottom: 20px;
  padding: 10px 30px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.d-flex {
  display: flex;
  align-items: center;
}
.mr-10 {
  margin-right: 10px;
}
.item /deep/ .is-dot {
  left: -31px;
  right: auto;
  top: 31px;
  width: 12px;
  height: 12px;
  background-color: #2b333e;
}
</style>
